#!/usr/bin/env python  
#coding=utf-8  
###################################  
# @author migle  
# @date 2010-01-17  
##################################  
#MySQLdb 示例  
#  

import urllib  
import os
import Queue
import copy
import pickle
#str = "manual\r\nhttp://baidu.com\r\nhttpsina.com\r\n"
#lsitru = str[8:].split("\r\n")
#for url in lsitru:
#    print (url)

sCommandLog = "Input #0, matroska,webm, from '../tmp/looper.mkv':\r\
  Duration: 00:01:48.19, start: 0.000000, bitrate: 4603 kb/s\r\
    Stream #0:0(eng), 43, 1/1000: Video: h264 (Main), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 417083/20000000, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)\r\
    Stream #0:1, 80, 1/1000: Audio: aac, 44100 Hz, stereo, s16 (default)\r\
[buffer @ 0x3236340] w:1280 h:720 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:\r\
[scale @ 0x3238de0] w:1280 h:720 fmt:yuv420p -> w:352 h:288 fmt:yuv420p flags:0x4"
vdict = {}

nInput = sCommandLog.find("Input")
temps = sCommandLog[nInput+6:sCommandLog.find(":", nInput)]
vdict["Input"] = temps

nDuration = sCommandLog.find("Duration:")
temps = sCommandLog[nDuration+10:sCommandLog.find(",", nDuration)]
vdict["Duration"]=temps

nstart = sCommandLog.find("start:")
temps = sCommandLog[nstart+7:sCommandLog.find(",", nstart)]
vdict["start"]=temps

nbitrate = sCommandLog.find("bitrate:")
temps = sCommandLog[nbitrate+9:sCommandLog.find(",", nbitrate)]
vdict["bitrate"]=temps

nVideo = sCommandLog.find("Video:")
temps = sCommandLog[nVideo+7:sCommandLog.find("\r", nVideo)]
tempList = temps.split(",")
vdict["Video"]=tempList

nAudio = sCommandLog.find("Audio:")
temps = sCommandLog[nAudio+7:sCommandLog.find("\r", nAudio)]
tempList = temps.split(",")
vdict["Audio"]=tempList

nbuffer = sCommandLog.find("buffer @")
tempdict = {}
tempdict["w"]=sCommandLog[sCommandLog.find("w:", nbuffer)+2:sCommandLog.find("h:", nbuffer)]
tempdict["h"]=sCommandLog[sCommandLog.find("h:", nbuffer)+2:sCommandLog.find("pixfmt:", nbuffer)]
tempdict["pixfmt"]=sCommandLog[sCommandLog.find("pixfmt:", nbuffer)+7:sCommandLog.find("\r", nbuffer)]
vdict["buffer"]=tempdict

nscale = sCommandLog.find("scale @")
tempdict = {}
tempdict["w"]=sCommandLog[sCommandLog.find("w:", nscale)+2:sCommandLog.find("h:", nscale)]
tempdict["h"]=sCommandLog[sCommandLog.find("h:", nscale)+2:sCommandLog.find("pixfmt:", nscale)]
tempdict["fmt"]=sCommandLog[sCommandLog.find("fmt:", nscale)+4:sCommandLog.find("\r", nscale)]
vdict["scale"]=tempdict

ss = pickle.dumps(vdict)

print (vdict)
